(function () {
    /**
     * 大厅页房间入口UI
     * 
     * @param {Number} level 房间等级
     * @param {Function} callback 点击房间以后的回调函数
     */
    function RoomLevelUI(level, callback) {
        RoomLevelUI.super(this);
        this.isOpen = null;

        this.CallBack = callback;
        this.isAnimation = false;

        this.setup(level);
        this.bindEvent();
    }
    Laya.class(RoomLevelUI, "ui.Com.RoomLevel", ui.Home.UI.RoomLevelUI);

    var _proto = RoomLevelUI.prototype;
    /**
     * @privite
     * 设置大厅界面房间入口的背景和位置
     * 
     * @param {String} level 房间等级{1:初级房，2:中级房，3:高级房}
     */
    _proto.setup = function (level) {
        this.levelbg.skin = "res/home/home_level_" + level + ".png";

        this.anchorY = 0.5;

        this.centerX = 0;
        this.y = 358 + 324 * (level - 1) + 162;
    }
    /**
     * @privite
     * 房间入口按钮绑定事件
     */
    _proto.bindEvent = function () {
        this.on(Laya.Event.CLICK, this, function () {
            if(this.isAnimation){return;}
            
            this.isAnimation = true;
            var timeline = new Laya.TimeLine;

            timeline
                .to(this, {scaleX : 0.94, scaleY : 0.94, alpha : 0.7}, 50, null, 0)
                .to(this, {scaleX : 1, scaleY : 1, alpha : 1}, 50, null, 0)
                .play(0, false);

            timeline.on(Laya.Event.COMPLETE, this, function () {
                this.isAnimation = false;

                if(this.isOpen){
                    if(this.CallBack && typeof this.CallBack === "function"){
                        this.CallBack(this.roomId);
                    }
                }else{
                    utils.log("房间已关闭！RoomId:" + this.roomId);
                    viewer.publish("alert.tip", "此房间已关闭！", 3000, 0.7);
                }
                timeline.destroy();
                timeline = null;
            });
        });
    }
    /**
     * @public
     * 更新大厅房间信息
     * 
     * @param {Object} data 房间信息,格式为{against : 100, online : 10, ante : 2000, roomId : 1};
     */
    _proto.update = function (data) {
        this.minCoin.changeText(data.against);
        this.lineNum.changeText(data.online);
        this.betCoin.changeText(data.ante + ":");
        this.roomId = data.roomId;
        this.isOpen = data.isOpen;

        //如果房间关闭，则此入口变灰
        this.disabled = !data.isOpen;
    }
})();